package action_行为型.memento_pattern_备忘录模式;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: hihi
 * @Date: 2020/07/08/19:59
 * @Description:
 */
public class MementoPatternDemo {
	public static void main(String[] args) {
		CareTaker careTaker = new CareTaker();
		Originator originator = new Originator("#1");
		originator.setState("#2");
		careTaker.add(originator.saveStateToMemento());
		originator.setState("#3");
		careTaker.add(originator.saveStateToMemento());
		originator.setState("#4");
		careTaker.add(originator.saveStateToMemento());
		originator.setState("#5");
		originator.setState("#6");
		System.err.println("current: " + originator.getState());
		originator.getStateFromMemento(careTaker.get(0));
		System.out.println("First saved State: " + originator.getState());
		originator.getStateFromMemento(careTaker.get(1));
		System.out.println("Second saved State: " + originator.getState());
	}

}
